// ex7_13_6.cpp
int Fill_array(double arr[], int n);
int Fill_array(double arr[], int n);
#include <iostream>
int Fill_array(double arr[], int n);
void Show_array(double arr[], int n);
void Reverse_array(double arr[], int n);

int main(void)
{
    using namespace std;
    const int size = 5;
    int cnt = 0;
    double num, arr[size];
    /*cout << "Enter double " << size << " number: " ;
    while ((cin >> num))
    {
        arr[cnt] = num;
        ++cnt;
        if (cnt == size)
            break;
        cout << "Enter double number: (Enter q to quit.) ";
    }*/
	cnt = Fill_array(arr, size);
    Show_array(arr, cnt);
	Reverse_array(arr, cnt);
    Show_array(arr, cnt);
	/*double tmp;
	for (int i = 1, j = cnt - 2; i < (cnt-1) / 2; i++, j--)
	{
		tmp = arr[i];
		arr[i] = arr[j];
		arr[j] = tmp;
	}*/
	// first and last index stayed
	Reverse_array(arr+1, cnt-2);
    Show_array(arr, cnt);
}

int Fill_array(double arr[], int n)
{
	using std::cout;
	using std::cin;
	double num;
	int cnt = 0;
    cout << "Enter double " << n << " number: " ;
    while ((cin >> num))
    {
        arr[cnt] = num;
        ++cnt;
        if (cnt == n)
            break;
        cout << "Enter double number: (Enter q to quit.) ";
    }
	return cnt;
}

void Show_array(double arr[], int n)
{
    using std::cout;
    for (int i = 0; i < n; i++)
    {
        cout << arr[i] << " ";
    }
    cout << "\n";
}

void Reverse_array(double arr[], int n)
{
	double tmp;
	//int tail = n - 1;
	for (int i = 0, tail = n - 1; i < n / 2;i++, tail--)
	{
		tmp = arr[i];
		arr[i] = arr[tail];
		arr[tail] = tmp;
	}
}

